package ListInterface;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 李泽伟
 */
public class MainTest {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        for(int i =0;i<100;i++){
            list.add(i);
            System.out.println(list.size());
        }
        LinkedList linkedList = new LinkedList();
    }
    @Test
    public void test(){
        ArrayList list = new ArrayList();
        // add()
        list.add("aa");
        list.add("bb");
        list.add(1, "cc");
        list.add("aa");
        //addAll()
        System.out.println(list);
        //get(idx);
        System.out.println(list.get(1));
        //indexOf()
        System.out.println(list.indexOf("aa"));
        //lastIndexOf()
        System.out.println(list.lastIndexOf("aa"));
        //remove(idx)
        list.remove(1);
        System.out.println(list);
        //set(idx, obj)
        list.set(1, "hh");
        System.out.println(list);
        //subList(firstIdx, endIdx)
        List list1 = list.subList(1, 2);
        System.out.println(list1);
        System.out.println(list);
        // 遍历 1.迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        //2.增强for
        for (Object li:list) {
            System.out.println(li);
        }
        //3.普通
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
    }
}
